package com.hxkj.controller;

import com.hxkj.domain.po.WebsiteAddr;
import com.hxkj.service.taglib.WebsiteAddrService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * url规则配置控制器
 * <p>
 * Created by chenfangzhou on 2018/8/9.
 */
@RestController
@RequestMapping("/website")
public class WebsiteAddrController {


    @Autowired
    private WebsiteAddrService websiteAddrService;


    /**
     * 获取url规则配置列表 带分页
     */
    @RequestMapping(value = "/getpages", method = RequestMethod.POST)
    public Callable<ResultPageStruct<WebsiteAddr>> getPages(@ModelAttribute WebsiteAddr websiteAddr, @ModelAttribute PageTo pageParam) throws Exception {
        return () -> websiteAddrService.getPages(websiteAddr == null ? new WebsiteAddr() : websiteAddr,pageParam);
    }

    /**
     * 获取url规则配置列表 不带分页
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<List<WebsiteAddr>> getList(@ModelAttribute WebsiteAddr websiteAddr) throws Exception {
        return () -> websiteAddrService.getList(websiteAddr == null ? new WebsiteAddr() : websiteAddr);
    }

    /**
     * 获取单一url规则配置
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public Callable<ResultDataStruct<WebsiteAddr>> get(@ModelAttribute WebsiteAddr websiteAddr) throws Exception {
        return () -> websiteAddrService.get(websiteAddr);
    }


    /**
     * 新增url规则配置
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResultMessageStruct save(@ModelAttribute WebsiteAddr websiteAddr) throws Exception {
        return websiteAddrService.save(websiteAddr);
    }

    /**
     * 修改url规则配置
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public ResultMessageStruct updateNotice(@ModelAttribute WebsiteAddr websiteAddr) throws Exception {
        return websiteAddrService.update(websiteAddr);
    }

    /**
     * 删除url规则配置
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public ResultMessageStruct deleteNotice(@ModelAttribute WebsiteAddr websiteAddr) throws Exception {
        return websiteAddrService.delete(websiteAddr);
    }

}
